/**
 * 表单样式组件库
 * 统一表单相关的样式规范
 */

// 导入变量和颜色模块
@use '../variables.scss' as *;
@use 'sass:color';

// ==================== 表单容器样式 ====================
.form {
  &-container {
    background: #fff;
    border-radius: $border-radius-lg;
    box-shadow: $shadow;
    padding: $spacing-lg;
    margin-bottom: $spacing-lg;

    &--bordered {
      border: 1px solid $border-color;
    }

    &--flat {
      box-shadow: none;
      background: transparent;
    }
  }

  &-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: $spacing-lg;
    padding-bottom: $spacing-md;
    border-bottom: 1px solid $border-color-lighter;

    &__title {
      font-size: $font-size-large;
      font-weight: $font-weight-bold;
      color: $text-color;
      margin: 0;
    }

    &__actions {
      display: flex;
      gap: $spacing-sm;
    }
  }

  &-body {
    margin-bottom: $spacing-lg;
  }

  &-footer {
    display: flex;
    justify-content: flex-end;
    gap: $spacing-sm;
    padding-top: $spacing-md;
    border-top: 1px solid $border-color-lighter;

    &--center {
      justify-content: center;
    }

    &--space-between {
      justify-content: space-between;
    }
  }
}

// ==================== 表单项样式 ====================
.form-item {
  margin-bottom: $form-item-margin-bottom;

  &--inline {
    display: inline-block;
    margin-right: $spacing-lg;
    margin-bottom: $spacing-md;
  }

  &--required {
    .form-item__label {
      &::before {
        content: '*';
        color: $danger-color;
        margin-right: $spacing-xs;
      }
    }
  }

  &--error {
    .form-item__control {
      .input__wrapper,
      .el-input__wrapper,
      .el-select__wrapper,
      .el-textarea__inner {
        border-color: $danger-color;
      }
    }
  }

  &__label {
    display: block;
    margin-bottom: $spacing-xs;
    font-size: $font-size-base;
    font-weight: $form-label-font-weight;
    color: $form-label-color;
    line-height: $line-height-base;

    &--required {
      &::before {
        content: '*';
        color: $danger-color;
        margin-right: $spacing-xs;
      }
    }
  }

  &__control {
    position: relative;
  }

  &__error {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: $spacing-xs;
    font-size: $font-size-small;
    color: $danger-color;
    line-height: $line-height-small;
  }

  &__help {
    margin-top: $spacing-xs;
    font-size: $font-size-small;
    color: $text-color-secondary;
    line-height: $line-height-small;
  }
}

// ==================== 输入框增强样式 ====================
.input-enhanced {
  position: relative;

  &__wrapper {
    position: relative;
    transition: $transition-base;

    &:hover {
      .input-enhanced__line {
        opacity: 1;
      }
    }

    &.is-focus {
      .input-enhanced__line {
        width: 100%;
        opacity: 1;
      }
    }
  }

  &__line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, $primary-color, color.adjust($primary-color, $lightness: 20%));
    transition: width $transition-base, opacity $transition-base;
    opacity: 0;
    border-radius: 1px;
  }

  &__prefix,
  &__suffix {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: $text-color-placeholder;
    z-index: 1;
  }

  &__prefix {
    left: $spacing-sm;
  }

  &__suffix {
    right: $spacing-sm;
  }

  &__inner {
    width: 100%;
    padding: $spacing-sm $spacing-md;
    border: 1px solid $border-color;
    border-radius: $border-radius;
    font-size: $font-size-base;
    color: $text-color;
    background: #fff;
    transition: $transition-base;

    &:focus {
      outline: none;
      border-color: $primary-color;
      box-shadow: 0 0 0 2px rgba($primary-color, 0.1);
    }

    &::placeholder {
      color: $text-color-placeholder;
    }

    &:disabled {
      background-color: $bg-color-page;
      color: $text-color-disabled;
      cursor: not-allowed;
    }
  }
}

// ==================== 搜索表单样式 ====================
.search-form {
  background: #fff;
  padding: $spacing-lg;
  border-radius: $border-radius-lg;
  margin-bottom: $spacing-lg;
  box-shadow: $shadow;

  &--inline {
    .el-form {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-end;
      gap: $spacing-md;

      .el-form-item {
        margin-bottom: 0;
        margin-right: 0;
      }
    }
  }

  &--compact {
    padding: $spacing-md;
    margin-bottom: $spacing-md;

    .el-form-item {
      margin-bottom: $spacing-sm;
    }
  }

  &__actions {
    display: flex;
    gap: $spacing-sm;
    align-items: center;
    margin-top: $spacing-md;

    &--right {
      justify-content: flex-end;
    }

    &--center {
      justify-content: center;
    }
  }
}

// ==================== 表单验证样式 ====================
.form-validation {
  &--error {
    .el-input__wrapper,
    .el-select__wrapper,
    .el-textarea__inner {
      border-color: $danger-color;
    }

    .el-input__inner:focus {
      box-shadow: 0 0 0 2px rgba($danger-color, 0.1);
    }
  }

  &--success {
    .el-input__wrapper,
    .el-select__wrapper,
    .el-textarea__inner {
      border-color: $success-color;
    }

    .el-input__inner:focus {
      box-shadow: 0 0 0 2px rgba($success-color, 0.1);
    }
  }

  &--warning {
    .el-input__wrapper,
    .el-select__wrapper,
    .el-textarea__inner {
      border-color: $warning-color;
    }

    .el-input__inner:focus {
      box-shadow: 0 0 0 2px rgba($warning-color, 0.1);
    }
  }
}

// ==================== 表单组样式 ====================
.form-group {
  margin-bottom: $spacing-lg;

  &__title {
    font-size: $font-size-base;
    font-weight: $font-weight-medium;
    color: $text-color;
    margin-bottom: $spacing-md;
    padding-bottom: $spacing-xs;
    border-bottom: 1px solid $border-color-lighter;
  }

  &__content {
    padding-left: $spacing-md;
  }

  &--collapsible {
    .form-group__title {
      cursor: pointer;
      user-select: none;
      position: relative;

      &::after {
        content: '▼';
        position: absolute;
        right: 0;
        transition: transform $transition-base;
      }

      &.collapsed::after {
        transform: rotate(-90deg);
      }
    }

    .form-group__content {
      overflow: hidden;
      transition: all $transition-base;

      &.collapsed {
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
      }
    }
  }
}

// ==================== 表单布局样式 ====================
.form-layout {
  &--horizontal {
    .form-item {
      display: flex;
      align-items: flex-start;

      .form-item__label {
        width: 120px;
        flex-shrink: 0;
        margin-right: $spacing-md;
        margin-bottom: 0;
        text-align: right;
        padding-top: $spacing-sm;
      }

      .form-item__control {
        flex: 1;
      }
    }
  }

  &--vertical {
    .form-item {
      .form-item__label {
        display: block;
        margin-bottom: $spacing-xs;
      }
    }
  }

  &--inline {
    .form-item {
      display: inline-block;
      margin-right: $spacing-lg;
      margin-bottom: $spacing-md;
      vertical-align: top;
    }
  }
}

// ==================== 响应式表单样式 ====================
@media (max-width: $breakpoint-sm) {
  .form {
    &-container {
      padding: $spacing-md;
      margin-bottom: $spacing-md;
    }

    &-header {
      flex-direction: column;
      align-items: flex-start;
      gap: $spacing-md;

      &__actions {
        width: 100%;
        justify-content: flex-start;
      }
    }

    &-footer {
      flex-direction: column;
      gap: $spacing-sm;

      .btn {
        width: 100%;
      }
    }
  }

  .form-layout--horizontal {
    .form-item {
      flex-direction: column;

      .form-item__label {
        width: auto;
        text-align: left;
        margin-bottom: $spacing-xs;
      }
    }
  }

  .search-form {
    &--inline {
      .el-form {
        flex-direction: column;
        align-items: stretch;

        .el-form-item {
          width: 100%;
        }
      }
    }
  }
}

// ==================== 特殊表单样式 ====================
.form-steps {
  margin-bottom: $spacing-lg;

  .el-steps {
    .el-step__title {
      font-size: $font-size-base;
      font-weight: $font-weight-medium;
    }

    .el-step__description {
      font-size: $font-size-small;
      color: $text-color-secondary;
    }
  }
}

.form-tabs {
  .el-tabs__header {
    margin-bottom: $spacing-lg;
  }

  .el-tabs__content {
    padding: $spacing-lg 0;
  }
}

.form-drawer {
  .el-drawer__body {
    padding: $spacing-lg;
  }

  .form-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: $spacing-md $spacing-lg;
    border-top: 1px solid $border-color-lighter;
    margin: 0 (-$spacing-lg) (-$spacing-lg);
  }
}
